﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Toolkit.Web.Infastructure;
using Toolkit.Web.ExtensionMethods;

namespace Toolkit.Web.ViewComponents.Button
{
    public sealed class ButtonMenuSectionBuilder
    {
        private ButtonMenuSection _buttonMenuSection;

        public ButtonMenuSectionBuilder(ButtonMenuSection component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            _buttonMenuSection = component;
        }

        public ButtonMenuSectionBuilder HtmlAttributes(object htmlAttributes)
        {
            if (htmlAttributes != null)
            {
                _buttonMenuSection.HtmlAttributes.Merge(htmlAttributes, true);
            }

            return this;
        }

        public ButtonMenuSectionBuilder AddItem(Action<object, IViewComponentWriter> template)
        {
            if (template != null)
            {
                _buttonMenuSection.Items.Add(new HtmlTemplate()
                {
                    ActionTemplate = template
                });
            }

            return this;
        }

        public ButtonMenuSectionBuilder AddItem(Func<object, object> template)
        {
            if (template != null)
            {
                _buttonMenuSection.Items.Add(new HtmlTemplate()
                {
                    InlineTemplate = template
                });
            }

            return this;
        }
    }
}
